export default ({ chartConfig, data, chartIns }) => {
  const xData = [];
  const yLeftData = [];
  const yRightData = [];
  data.forEach(item => {
    xData.push(item[chartConfig.x_axis]);
    yLeftData.push(item[chartConfig.left_y_axis]);
    yRightData.push(item[chartConfig.right_y_axis]);
  });
  const maxLeftYData = Math.max(...yLeftData);
  const maxRightYData = Math.max(...yRightData);
  const option = {
    tooltip: {
      show: true,
      trigger: 'axis',
      backgroundColor: 'rgba(50,50,50,0.7)',
      borderColor: 'rgba(50,50,50,0.7)',
      textStyle: {
        color: '#fff'
      },
      // 自定义提示框内容
      formatter: params => {
        let result = `${params[0].name}<br/>`;
        params.forEach(param => {
          result += `${param.seriesName}: ${param.value}<br/>`;
        });
        return result;
      }
    },
    legend: {
      show: true,
      top: 0,
      left: 'left',
      textStyle: {
        fontFamily: 'PingFangSC-Regular',
        fontSize: 12,
        color: 'rgba(255,255,255,0.60)',
        fontWeight: 400
      },
      itemWidth: 20,
      itemHeight: 6
    },
    xAxis: {
      type: 'category',
      data: xData,
      axisLine: {
        lineStyle: {
          color: 'rgba(255,255,255,0.06)'
        }
      },
      axisLabel: {
        textStyle: {
          color: 'rgba(255,255,255,0.6)',
          fontFamily: 'THS'
        },
      }
    },
    yAxis: [
      {
        type: 'value',
        max: Math.floor(maxLeftYData / 0.85),
        splitLine: {
          lineStyle: {
            color: 'rgba(255,255,255,0.06)'
          }
        },
        axisLabel: {
          textStyle: {
            color: 'rgba(255,255,255,0.6)',
            fontFamily: 'THS'
          }
        }
      },
      {
        type: 'value',
        max: Math.floor(maxRightYData / 0.85),
        axisLabel: {
          color: 'rgba(255,255,255,0.60)'
        },
        splitLine: {
          show: false
        }
      }
    ],
    series: [
      {
        type: 'line',
        name: chartConfig.left_y_axis,
        data: yLeftData,
        yAxisIndex: 0
      },
      {
        type: 'line',
        name: chartConfig.right_y_axis,
        data: yRightData,
        yAxisIndex: 1
      }
    ],
    grid: {
      top: 40,
      right: 12,
      bottom: 0,
      left: 12,
      containLabel: true
    }
  };
  chartIns.play({
    option
  });
  return chartIns;
};
